package edu.tec.mty.core.modules.models;

import java.util.Vector;

public class BallModelFactory {

	private int maxNumberOfBalls = 64;
	private int currentHistorySize = 0;
	private int lifeSpan = 32;
	private Vector<Ball> ballHistory = new Vector<Ball>();
	private int nextID = 0;
	
	public BallModelFactory() {
		
	}
	
	public void updateBall(Ball ball) {
		if (this.currentHistorySize == this.maxNumberOfBalls) {
			this.ballHistory.get(this.maxNumberOfBalls - 2).unbind();
			this.ballHistory.remove(this.maxNumberOfBalls - 1); 
		} else {
			this.currentHistorySize++;
		}
		if (this.ballHistory.size() == 0) {
			ball.setID(this.nextID++);
		} else {
			Ball firstBallOnStack = this.ballHistory.get(0);
			if (firstBallOnStack.isViewed()) {
				ball.setID(firstBallOnStack.getID());
			} else {
				ball.setID(this.nextID++);
			}
			ball.bindTo(this.ballHistory.get(0));
		}
		this.ballHistory.add(0, ball);
	}
	
	public BallModel getBallModel() {
		return new BallModel(new Ball());
	}
	
}
